<!-- 在这个文件对每个tab对应的列表进行渲染 -->
<template>
	<view class="paryorder-content">
		<!-- 这里设置了z-paging加载时禁止自动调用reload方法，自行控制何时reload（懒加载）-->
		<!--  :enable-back-to-top="currentIndex===tabIndex" 在微信小程序上可以多加这一句，因为默认是允许点击返回顶部的，但是这个页面有多个scroll-view，会全部返回顶部，所以需要控制是当前index才允许点击返回顶部 -->
		<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" :auto="true">
			<template #top>
				<view  style="background-color: #F8F8F8;">
					<fui-nav-bar title="选择经销商" isFixed isOccupy @leftClick="pageBack" ></fui-nav-bar>
				</view>
			</template>
			
			<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
			<view class="payorder-container" v-for="(item,index) in dataList" :key="index" >
				<view class="payorder-section">
					<image :src="item.url?item.url:defaultLogo" mode="" class="section-image" ></image>
					<view class="section-list">
						<view class="section-item">
							<view class="u-line-1 u-font-28">{{item.name}}</view>
							<fui-button width="100rpx" height="50rpx" radius="10rpx" size="28" background="#fff" color="#606266" borderColor="#c0c4cc" @click="itemClick(item)">选择</fui-button>
						</view>
					</view>
					
				</view>
			</view>
			
		</z-paging>
		
	</view>
</template>

<script>
	import {useShopStore} from '@/store/shop.js';
	import { mapState } from 'pinia';
	export default {
		data() {
			return {
				//v-model绑定的这个变量不要在分页请求结束中自己赋值！！！
				dataList: [],
			}
		},
		created(){
			// this.$refs.paging.reload();
		},
		computed:{
			...mapState(useShopStore, {
				storeShop: 'shop',
			})
		},
		methods: {
			async queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				console.log(222);
				const params = {
					pageIndex: pageNo,
					pageSize: pageSize,
					id:this.storeShop.id,
					IsSeller:false
				}
				uni.showLoading({
					title: 'loading...',
					mask: false
				});
				const res = await this.$newHttp.get('api/TradePayment/GetTradeAssociatedShops', { params: params } );
				uni.hideLoading({
					title: 'loading...'
				})
				if(res.code === 200){
					this.$refs.paging.complete(res.data.list);
				}else{
					this.$refs.paging.complete(false);
				}
			},
			itemClick(item) {
				console.log('点击了', item.title);
				this.$mRouter.push({ 
					route: '/pages/purchase/payorder/createPayOrder?shop='+item.id,
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 注意:父节点需要固定高度，z-paging的height:100%才会生效 */
	.paryorder-content {
		height: 100%;
		background-color: #f8f8f8;
	}
	.payorder-container{
		background-color: #fff;
		box-sizing: border-box;
		padding: 0 30rpx;
		.payorder-header{
			display: flex;
			justify-content: space-between;
		}
		.payorder-section{
			display: flex;
			align-items: center;
			box-sizing: border-box;
			padding: 30rpx 0;
			border-bottom: solid 1px #eaeaea;
			.section-image{
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
			}
			.section-list{
				flex: 1;
				margin-left: 20rpx;
				
				.section-item{
					display: flex;
					width: 100%;
					justify-content: space-between;
					align-items: center;
				}
			}
			
		}
		
	}


</style>
